<!DOCTYPE html>
<!--
Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/EmptyPHPWebPage.php to edit this template
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <a href="adduser.php">添加</a>
        <br/>
        <table border="1px">
            <tr>
                <th>编号</th>
                <th>用户名</th>
                <th>密码</th>
                <th>年龄</th>
                <th>性别</th>
                <th></th>
            </tr>
        <?php
       
        //mysql_connect 获取一个数据库的连接对象,返回值是连接对象或者false
        //shostname 表示连接的数据库的ip或者域名
        //$username 连接数据库使用的用户
        //$password 连接的用户的密码
        //$database 需要连接的数据库
        $hostname="127.0.0.1";
        $username="root";
        $password="";
        $database="mybb_text";
        $connect=mysqli_connect($hostname, $username, $password, $database);
        if($connect){
//           echo "数据库连接成功！";
           // mysqli_set_charset 设置连接使用的字符集
            mysqli_set_charset($connect,"utf-8");
            $sqlstring="INSERT INTO `mybb_text`.`user_yi` (`uid`, `username`, `upwd`, `age`, `sex`) "
                    . "VALUES ('1', '张三', '123456', '18', '女');";
            //mysql_query 执行sql语句并获得执行结果
            $sqlstring="select * from user_yi";
            $result=mysqli_query($connect, $sqlstring);
            //mysqli_fetch_array 获取结果集中某一行的记录
            $row= mysqli_fetch_array($result);
            while ($row){
//           // echo "<br/>\$row :".gettype($row);
//        //    foreach ($row as $k=>$v){
//          //      echo "<br/>".$k." -> ".$v;
//        //    }
//     //       echo "<br/> uid:".$row["uid"]." username:".$row["username"]."upwd:".$row["upwd"]
//       //         ." age:".$row["age"]." sex:".$row["sex"];
//        echo "<br/> uid:".$row["uid"]." username:".$row["username"]."upwd:".$row["upwd"]
//               ." age:".$row["age"]." sex:".$row["sex"];
        ?>
              <tr>
                  <td><?php echo $row["uid"]; ?></td>
                  <td><?php echo $row["username"]; ?></td>
                  <td><?php echo $row["upwd"]; ?></td>
                  <td><?php echo $row["age"]; ?></td>
                  <td><?php echo $row["sex"]; ?></td>
                  <td>
                      <a href="edituser.php?id=<?php echo $row["uid"]; ?>">编辑</a>
                      <a href="deluser.php?id=<?php echo $row["uid"]; ?>">删除</a>
                  </td>
              </tr>
        <?php
        $row=mysqli_fetch_array($result);
       }
       
        }else{
            echo "数据库连接失败";
        }
        //mysqli close 释放数据库连接
        mysqli_close($connect);
        ?>
        </table>
    </body>
</html>
